<template>
	<view>
		<goods :recommendList="recommendList"></goods>
		<view class="isOver" v-if="flag">-------到底了------</view>
	</view>
</template>

<script>
	import goods_cpn from "../../components/goods_cpn"
	export default {
		data() {
			return {
				recommendList:[],
				pageindex:1,
				flag:false
			}
		},
		components:{
			goods:goods_cpn
		},
		onLoad(){
			this.getRecommend()
		},
		methods: {
			async getRecommend(callBack){
				const res = await this.$myRequest({
					// 模拟
					url:'/recommend?pageindex='+this.pageindex
				})
				let data = res.data.data.list
				this.recommendList=[...this.recommendList,...data]
				callBack && callBack()
			},
		},
		onReachBottom(){
			if(this.pageindex>3) return this.flag=true
			this.pageindex++
			this.getRecommend()
		},
		onPullDownRefresh(){
			this.flag=false
			this.pageindex=1
			this.recommendList=[]
			setTimeout(()=>{
				this.getRecommend(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
		}
	}
</script>

<style lang="scss">
	.isOver{
		width:100%;
		height: 50px;
		line-height: 50px;
		text-align: center;
		font-size: 28rpx;
	}
</style>
